/*
 * CodeSaveCommand.java
 *
 * Created on 2006년 3월 29일 (수), 오후 4:11
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.welfare.admin;

import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.json.simple.JSONObject;

import com.zll.framework.model.HashBox;
import com.zll.framework.model.HashList;
import com.zll.framework.servlet.Command;
import com.welfare.common.CommonDAO;
import com.welfare.common.CommonUtil;





/**
 * 관리자 로그인
 * 
 * 권한종류(부서별 적용)
 * S : 슈퍼관리자, 복지정책과
 * U : 수정권한
 * R : 조회권한
 * @author eastar
 */
public class LoginCommand implements Command
{

    public String execute(HttpServletRequest  request, HttpServletResponse response)
    throws Exception
    {
		JSONObject json = new JSONObject();


    	HashBox box = new HashBox(request);

		CommonDAO dao 		= new CommonDAO();

		HashList list = dao.selectUserList(box.getParam());

		if (list.size() == 1) 
		{
			if ("".equals(list.get("auth_code",0))) {
				json.put("result", new Boolean(false));
				json.put("message", "사용권한이 없습니다. 관리자에게 문의하세요.");
			}
			else {
				json.put("result", new Boolean(true));
				json.put("nextUrl", "./main.jsp");
	
				HttpSession session = request.getSession();
				
				//session.setAttribute("session.user_id", 	list.get("user_id",0));
				session.setAttribute("session.user_id", 	list.get("dept_name",0) + " " + list.get("user_name",0));
				session.setAttribute("session.user_name", 	list.get("user_name",0));
				session.setAttribute("session.dept_name", 	list.get("dept_name",0));
				session.setAttribute("session.position", 	list.get("position",0));
				session.setAttribute("session.user_auth",   list.get("auth_code", 0));
			}

		} else {
			json.put("result", new Boolean(false));
			json.put("message", "아이디 또는 비밀번호를 확인하세요.");
		}

		request.setAttribute("jsonData", json.toString());


    	return "/common/json_view.jsp";
    }
}
